﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.BaseData
{
    public partial class AddTeacherInfo : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPageUserType.Add("mana");
            strPagePrivilege.Add("JSSJ");

            if (!IsPostBack)
            {
                InitBindDDl();
            }

            tbcsrq.Attributes.Add("readOnly", "true");
            tbgzrq.Attributes.Add("readOnly", "true");
            tbbysj.Attributes.Add("readOnly", "true");
            tbcsrq.Attributes.Add("OnClick", "c.showMoreDay=false;c.show(this);");
            tbgzrq.Attributes.Add("OnClick", "c.showMoreDay=false;c.show(this);");
            tbbysj.Attributes.Add("OnClick", "c.showMoreDay=false;c.show(this);");
        }

        /// <summary>
        /// 初始化性别下拉框绑定
        /// </summary>
        protected void InitBindDDl()
        {
            LabMS.BLL.Dictionary bd = new LabMS.BLL.Dictionary();
            string str = "DClass='201'";
            ddlSex.DataSource = bd.GetModelList(str);
            ddlSex.DataValueField = "Code";
            ddlSex.DataTextField = "Name";
            ddlSex.DataBind();
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region 验证
            if (string.IsNullOrEmpty(tbCode.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "教师编号不能为空！");
                tbCode.Focus();
            }
            else if (string.IsNullOrEmpty(tbName.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "老师名称不能为空！");
                tbName.Focus();
            }
            else if (string.IsNullOrEmpty(tbPassword.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page,"","密码不能为空！");
                tbPassword.Focus();
            }
            #endregion
            else
            {
                LabMS.Model.Teacher MT = new LabMS.Model.Teacher();
                MT.CardCode = tbkpCode.Text.Trim();
                MT.ComeFrom = tbcs.Text.Trim();
                MT.Dirthday = DateTime.Parse(tbcsrq.Text.Trim());
                MT.Education = tbwhcd.Text.Trim();
                MT.Email = tbEmail.Text.Trim();
                MT.Fax = tbFax.Text.Trim();
                MT.GDate = DateTime.Parse(tbbysj.Text.Trim());
                MT.GSchool = tbbyxx.Text.Trim();
                MT.Health = tbjkzk.Text.Trim();
                MT.HomeAddress = tbhomeAdd.Text.Trim();
                MT.Homephone = tbhomeTel.Text.Trim();
                MT.Jobs = tbzw.Text.Trim();
                MT.Marriage = tbhyzk.Text.Trim();
                MT.Mobile = tbPhone.Text.Trim();
                MT.Nation = tbmz.Text.Trim();
                MT.OfficeAddress = tbOfficeAdd.Text.Trim();
                MT.Political = tbzzmm.Text.Trim();
                MT.Professional = tbjszc.Text.Trim();
                MT.Province = tbPro.Text.Trim();
                MT.SexCode = ddlSex.SelectedValue.ToString();
                MT.Specially = tbzyjstc.Text.Trim();
                MT.Teacher_Code = tbCode.Text.Trim();
                MT.Teacher_Name = tbName.Text.Trim();
                MT.Tel = tbOfficeTel.Text.Trim();
                MT.WorkDate = DateTime.Parse(tbgzrq.Text.Trim());
                MT.Password = tbPassword.Text.Trim();
                LabMS.BLL.Teacher BT = new LabMS.BLL.Teacher();
                int a = BT.Add(MT);
                if (a > 0)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('新增成功！');window.opener.location.href=window.opener.location.href;self.close();</script>");
                }
            }
        }
    }
}
